const mongoose = require('mongoose');

const paymentSchema = new mongoose.Schema({
  userId: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true }, // 支付人（寄养人）
  postId: { type: mongoose.Schema.Types.ObjectId, ref: 'Post', required: true },
  amount: { type: Number, required: true },
  status: { type: String, enum: ['pending', 'completed', 'failed', 'refunded'], default: 'pending' },
  paymentMethod: String,
  transactionId: String,
  type: { type: String, enum: ['foster_payment', 'service_fee'], default: 'foster_payment' }, // 支付类型
  fosterUserId: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }, // 收养人ID
  platformFee: { type: Number, default: 0 }, // 平台服务费
  fosterAmount: { type: Number, default: 0 }, // 实际给收养人的金额
  createdAt: { type: Date, default: Date.now }
});

module.exports = mongoose.model('Payment', paymentSchema);